/*
 * @Author: your name
 * @Date: 2021-04-18 11:33:24
 * @LastEditTime: 2021-05-01 15:51:46
 * @LastEditors: Please set LastEditors
 * @Description: 点餐界面中间的listview
 * @FilePath: /first_flutter_app/lib/views/orderPage/orderMiddleListView.dart
 */

import 'package:first_flutter_app/constant/dataInfo.dart';
import 'package:first_flutter_app/controller/orderPageController.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class PaymentMiddlePageShow extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return _listSetting();
  }

  Widget _listSetting() {
    return Container(
      width: 279.w,
      // height: 1950.h,
      padding: EdgeInsets.all(ScreenUtil().setSp(30)),
      // decoration: BoxDecoration(
      //   color: Color.fromRGBO(243, 245, 247, 1.5),
      //   border: Border.all(
      //     color: Color.fromRGBO(233, 236, 245, 1),
      //   ),
      // ),
      child: Column(
        children: [
          _memberLoginContainer(),
          _listPaymentSetting(),
          // Divider(color: Colors.black45),
          // _listOrderSetting(),
        ],
      ),
    );
  }

  // 会员登录组件
  Widget _memberLoginContainer() {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border.all(
          color: Colors.black12,
        ),
      ),
      padding: EdgeInsets.fromLTRB(0, 20, 0, 20),
      child: Column(
        children: [
          InkWell(
            onTap: () {},
            child: Container(
              width: 250.w,
              height: 150.h,
              child: Center(
                child: Container(
                  padding: EdgeInsets.fromLTRB(20, 5, 20, 5),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(
                      Radius.circular(8.0),
                    ),
                    border: Border.all(
                      color: Colors.black12,
                    ),
                  ),
                  child: Text(
                    "顾客登录/注册",
                    style: TextStyle(
                      fontSize: ScreenUtil().setSp(50),
                      color: Colors.blue,
                    ),
                  ),
                ),
              ),
            ),
          ),
          Container(
            margin: EdgeInsets.only(top: ScreenUtil().setSp(10)),
            child: Text(
              "会员登录后才可以使用积分",
              style: TextStyle(
                  fontSize: ScreenUtil().setSp(30), color: Colors.grey),
            ),
          ),
        ],
      ),
    );
  }

  Widget _listPaymentSetting() {
    return Container(
      height: 1500.h,
      decoration: BoxDecoration(
        color: Colors.white,
      ),
      child: Column(
        children: [
          Row(
            children: [
              _listInkWell("发券", "images/discpage.png"),
              _listInkWell("折扣", "images/disc.png"),
            ],
          ),
          Row(
            children: [
              _listInkWell("附加费", "images/orderpay.png"),
              _listInkWell("卡券", "images/card.png"),
            ],
          ),
          Row(
            children: [
              _listInkWell("优惠活动", "images/event.png"),
            ],
          ),
        ],
      ),
    );
  }

  Widget _listInkWell(String bottomText, String imageUrl) {
    return               InkWell(
      onTap: () {},
      child: Container(
        height: 350.h,
        // width: 200.w,
        child: Center(
          child: Container(
            width: 125.w,
              // padding: EdgeInsets.only(
              //   left: 36.w,
              //   right: 35.w,
              // ),
              decoration: BoxDecoration(
                border: Border.all(
                  color: Colors.black12,
                ),
              ),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Container(
                    padding: EdgeInsets.only(
                      bottom: 20.h
                    ),
                    child: Image(
                      image: AssetImage(imageUrl),
                      width: 50.w
                    ),
                  ),
                  Text(
                    bottomText,
                    style: TextStyle(
                      fontSize: 40.sp,
                      color: Colors.black54
                    ),
                  ),
                ],
              )
          ),
        ),
      ),
    );
  }

  Widget _listOrderSetting() {
    return Container(
      height: ScreenUtil().setHeight(820),
      // width: ScreenUtil().setWidth(80),
      child: ListView.builder(
        itemBuilder: (context, index) {
          return GetBuilder<OrderController>(
            builder: (_) => Container(
              margin: EdgeInsets.all(ScreenUtil().setSp(20)),
              child: ElevatedButton(
                onPressed: () {
                  showDialog(
                    context: context,
                    builder: (BuildContext context) {
                      return AlertDialog(
                        title: Text(
                          '警告',
                          style: TextStyle(
                            color: Colors.blueAccent,
                            fontSize: 25.0,
                          ),
                        ),
                        content: Text(
                          '是否确定删除这些菜品?',
                          style: TextStyle(
                            color: Colors.black54,
                            fontSize: 25.0,
                          ),
                        ),
                        actions: [
                          GetBuilder<OrderController>(
                            builder: (_) => ElevatedButton(
                              onPressed: () {
                                OrderController.oc.deleteSelectProductList();
                                Navigator.pop(context);
                              },
                              child: Text(
                                "确定",
                                style: TextStyle(
                                  fontSize: ScreenUtil().setSp(30),
                                ),
                              ),
                            ),
                          ),
                          ElevatedButton(
                            onPressed: () {
                              Navigator.pop(context);
                            },
                            style: ButtonStyle(
                              backgroundColor:
                                  MaterialStateProperty.resolveWith((states) {
                                //设置按下时的背景颜色
                                if (states.contains(MaterialState.pressed)) {
                                  return Colors.blue;
                                }
                                //默认不使用背景颜色
                                return Colors.green;
                              }),
                            ),
                            child: Text(
                              "取消",
                              style: TextStyle(
                                fontSize: ScreenUtil().setSp(30),
                              ),
                            ),
                          ),
                        ],
                      );
                    },
                  );
                },
                style: ButtonStyle(
                  minimumSize: MaterialStateProperty.all(Size(120, 50)),
                  backgroundColor: MaterialStateProperty.resolveWith((states) {
                    //设置按下时的背景颜色
                    if (states.contains(MaterialState.pressed)) {
                      return Colors.blue[800];
                    }
                    //默认不使用背景颜色
                    return Colors.white;
                  }),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    orderSetting[index][0],
                    Text(
                      orderSetting[index][1],
                      style: TextStyle(
                        color: Colors.black45,
                        fontSize: ScreenUtil().setSp(50),
                        fontWeight: FontWeight.w900,
                      ),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    ),
                  ],
                ),
              ),
            ),
          );
        },
        itemCount: orderSetting.length,
      ),
    );
  }
}
